package com.mao.controller;

import com.alibaba.fastjson.JSONObject;
import com.mao.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Author Kechelle
 * @Date 2020/9/7 20:35
 * @Version 1.0
 */
@RestController
@Controller
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping(value = "/admin/login/status",method = RequestMethod.POST)
    public Object loginStatus(HttpServletRequest request, HttpSession session){
        //创建Json封装对象
        JSONObject jsonObject = new JSONObject();

        //获取请求的用户名和密码
        String name = request.getParameter("name");
        String password = request.getParameter("password");

        boolean res = adminService.verifyPassword(name,password);
        //账户验证成功
        if (res){
            jsonObject.put("code",1);
            jsonObject.put("msg","登录成功！");
            session.setAttribute("name",name);
        }else {
            jsonObject.put("code",0);
            jsonObject.put("msg","用户名 或密码错误！");
        }
        return jsonObject;
    }

}
